#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
// priority_queue<int, vector<int>, greater<int>> pq;

void solve() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(k == 0) {
        string t = s;
        reverse(t.begin(), t.end());
        if(s < t) {
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }else{
        string t(n, s[0]);
        if(s == t) {
            cout << "NO" << endl;
        }else{
            cout << "YES" << endl;
        }
    }
}

signed main() {
    int t = 1;
    cin >> t;
    while(t--) solve();
    return 0;
}